<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>{$title}</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-4">
                <input type="text" name="title" lay-verify="required" placeholder="{:lang('pleaseEnter')}标题" class="layui-input" value="{$info.title|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板</label>
            <div class="layui-input-4">
                <select name="template" lay-verify="required">
                    <option value="">请选择广告模板</option>
                    {volist name="template" id='vo'}
                        <option value="{$vo.value}" {if $info != 'null' && $vo['value'] == $info['template']} selected{/if}>{$vo.filename}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">宽：</label>
            <div class="layui-input-4">
                <input type="text" name="width" value="{$info.width|default=''}" placeholder="图片宽度" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">高：</label>
            <div class="layui-input-4">
                <input type="text" name="height" value="{$info.height|default=''}" placeholder="图片高度" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数量：</label>
            <div class="layui-input-4">
                <input type="text" name="num" value="{$info.num|default=''}"  placeholder="数量" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否显示</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" {if $info == 'null' || $info['status']==1} checked {/if}title="{:lang('open')}">
                <input type="radio" name="status" value="0" {if $info != 'null' && $info['status']==0} checked {/if}title="{:lang('close')}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('order')}</label>
            <div class="layui-input-4">
                <input type="text" name="sort" value="{$info.sort|default=''}"  placeholder="从小到大排序" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>

<script>
        layui.use(['form', 'layer','upload'], function () {
            var form = layui.form, $ = layui.jquery, upload = layui.upload;
             $('#adPic').attr('src', '');
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.id = '{$info.id|default=0}';
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });
            //普通图片上传
            var uploadInst = upload.render({
                elem: '#adBtn'
                ,url: '{:url("UpFiles/upload")}'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#adPic').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#pic').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg('上传失败');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
</script>